package iscte.ai.kcgtd;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;

public class CalendarEventsActivity extends Activity {

	private ArrayList<OccupiedBlocks> events;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list);
		
		Intent intent = getIntent();
		String strDate = intent.getStringExtra("iscte.ai.kcgtd.calendar_activity.event_date");
		String[] dateArr = strDate.split("-"); // date format is yyyy-mm-dd
		KCGTDTime date = new KCGTDTime(Integer.parseInt(dateArr[2]), Integer.parseInt(dateArr[1]), Integer.parseInt(dateArr[0]));
		
		KCGTDTime inicio_evento = new KCGTDTime(0, MainActivity.settings.getStartMinutes(), MainActivity.settings.getStartHour(), date.getMonthDay(), (date.getMonth()-1), date.getYear());
		KCGTDTime fim_evento = new KCGTDTime(0, MainActivity.settings.getEndMinutes(), MainActivity.settings.getEndHour(), date.getMonthDay(), (date.getMonth()-1), date.getYear());

		events = ProviderCalendar.getOccupiedBlocks(CalendarEventsActivity.this, inicio_evento, fim_evento);
		
		ListView list = (ListView) findViewById(R.id.list);
		EventsViewAdapter adapter = new EventsViewAdapter(this, events);
		list.setAdapter(adapter);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.calendar_events, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

}
